<template>
	<view class="container">
		<view class="home_wrapper" v-if="pageConfigData.length > 0">
			<view class="home_item" v-for="(item, index) in pageConfigData" :key="index">
				<xjsearch v-if="item.component == 'xjsearch'"></xjsearch>
				<xjgonggao v-if="item.component == 'xjgonggao'" :gonggao="item.gonggaotext" :prevent="false">
				</xjgonggao>
				<xjlunbotu v-if="item.component == 'xjlunbotu'" :lunbotu="item.swiperimg" :prevent="false"></xjlunbotu>
				<xjcategory v-if="item.component == 'xjcategory'" :category="item.categorydata" :prevent="false">
				</xjcategory>
				<xjtuwennav v-if="item.component == 'xjtuwennav'" :tuwennav="item.tuwennavimg" :prevent="false">
				</xjtuwennav>
				<xjdantu v-if="item.component == 'xjtuwennav'" :tuwennav="item.tuwennavimg" :prevent="false"></xjdantu>
				<xjcustomtext v-if="item.component == 'xjcustomtext'" :customtext="item.customtext" :prevent="false">
				</xjcustomtext>
				<xjeyegzh v-if="item.component == 'xjeyegzh'" :eyegzh="item.eyegzhtext" :prevent="false"></xjeyegzh>
				<xjuserservice v-if="item.component == 'xjuserservice'" :prevent="false"></xjuserservice>
				<xjyouhuinav v-if="item.component == 'xjyouhuinav'" :youhuinav="item.youhuinavimg" :prevent="false">
				</xjyouhuinav>
				<!-- 
					<component
						v-if="item.component ? true : false"
						:is="item.component"
						:customtext="item.customtext"
						:lunbotu="item.swiperimg"
						:dantu="item.dantuimg"
						:gonggao="item.gonggaotext"
						:eyegzh="item.eyegzhtext"
						:tuwennav="item.tuwennavimg"
						:youhuinav="item.youhuinavimg"
						:category="item.categorydata"
						:courselist="item.courselist"
						:prevent="false"></component>
				-->
			</view>
		</view>
		<view class="home_footer">
			<view class="home_link">
				<text>店铺主页</text>
				<text class="division_line">|</text>
				<text @click="GotoPersonCenter">个人中心</text>
				<text class="division_line">|</text>
				<text @click="GotoSuggestions">投诉建议</text>
			</view>
			<view class="message">知了提供技术支持</view>
			<view class="address">www.</view>
		</view>
		<PageNavBar :tabIndex="0" />
	</view>
</template>

<script>
	// https://www.nashicike.top/xuejing/my/chat/db   17671246177    abcde12345
	// https://www.nashicike.top/pages/my/index?shop_name=db&code=081XRS0w30eQK23Bsy3w3TYICt0XRS0p&state=STATE
	import {
		api_HomePageData
	} from '@/api/api'
	import {
		URLParams
	} from '@/utils/util'
	import * as type from '../../utils/device'
	import storage from '@/utils/storage.js'
	import xjsearch from '@/components/shop/xjsearch.vue'
	import xjcustomtext from '@/components/shop/xjcustomtext.vue'
	import xjlunbotu from '@/components/shop/xjlunbotu.vue'
	import xjdantu from '@/components/shop/xjdantu.vue'
	import xjgonggao from '@/components/shop/xjgonggao.vue'
	import xjeyegzh from '@/components/shop/xjeyegzh.vue'
	import xjtuwennav from '@/components/shop/xjtuwennav.vue'
	import xjyouhuinav from '@/components/shop/xjyouhuinav.vue'
	import xjcategory from '@/components/shop/xjcategory.vue'
	import xjuserservice from '@/components/shop/xjuserservice.vue'
	import xjcourselist from '@/components/shop/xjcourselist.vue'
	import PageNavBar from '@/components/nav_footer/index.vue'
	export default {
		components: {
			xjsearch,
			xjcustomtext,
			xjlunbotu,
			xjdantu,
			xjgonggao,
			xjeyegzh,
			xjtuwennav,
			xjcategory,
			xjuserservice,
			xjyouhuinav,
			xjcourselist,
			PageNavBar,
		},
		data() {
			return {
				pageConfigData: [],
			}
		},
		computed: {
			device() {
				return type.default;
			},
		},
		onLoad() {
			this.getUrl();
		},
		created() {
			// this.setShopName();
			this.getUrl();
		},
		methods: {
			getUrl() {
				// 获取当前页面的地址
				let url = window.location.href;

				// 使用正则表达式匹配地址栏中的动态部分
				let match = url.match(/https?:\/\/(\w+)\.edu\.hikaw\.top/);

				if (match) {
					let dynamicPart = match[1]; // 获取匹配到的动态部分
					storage.set('domainname', dynamicPart);
					this.init();
				} else {
					console.log("未匹配到动态部分");
					this.init();
				}

			},
			setShopName() { // 设置shopname
				// let page = getCurrentPages();
				// let path = null;
				// if (this.device == 'MP-WEIXIN') {
				// 	console.log('page',page);
				// 	path = page[page.length - 1].__route__;
				// 	console.log('path',path)
				// } else {					
				// 	path = page[page.length - 1].__page__.fullPath;					
				// }
				// let query = URLParams(path);

				let query = URLParams(window.location.href);
				if (Object.keys(query).length > 0) {
					query.shop_name && storage.set('domainname', query.shop_name);
					this.init();
				} else {
					if (!storage.get('domainname')) {
						uni.showToast({
							title: '链接地址缺少必要参数',
							icon: 'error'
						});
						return;
					} else {
						this.init();
					}
				}
			},
			init() { // 页面初始化				
				uni.showLoading({
					title: '数据加载中...'
				});
				api_HomePageData().then(res => {
					let {
						code,
						data,
						msg
					} = res;
					uni.hideLoading();
					if (code == 1) {
						this.pageConfigData = data.phonepagedata;
						this.tabbar = data.tabbar;
						storage.set('tabbar', data.tabbar);
						uni.$emit('triggerTabbar');
					} else {
						uni.showToast({
							title: msg,
							icon: 'error'
						});
					}
				}).catch(err => {
					uni.hideLoading();
					console.log(err);
				});

			},
			GotoPersonCenter() { // 个人中心
				uni.redirectTo({
					url: '/pages/my/index'
				});
			},
			GotoSuggestions() { // 投诉建议
				console.log('suggestions')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		height: calc(100vh - 100px);
		padding: 0 0 50px 0;
		overflow-y: auto;

		.home_wrapper {
			.home_item {}
		}

		/*
		<view class="home_footer">
			<view class="home_link">
				<text>店铺主页</text>
				<text class="division_line">|</text>
				<text>个人中心</text>
				<text class="division_line">|</text>
				<text>投诉建议</text>
			</view>
			<view class="message">知了提供技术支持</view>
			<view class="address">www.</view>
		</view>
	*/
		.home_footer {
			text-align: center;
			color: #6d737a;
			margin: 0 auto 20px;

			.home_link {
				font-size: 12px;
				line-height: 32px;

				.division_line {
					display: inline-block;
					margin: 0 5px;
				}
			}

			.message {
				font-size: 13px;
				line-height: 24px;
			}

			.address {
				font-size: 12px;
				line-height: 18px;
			}
		}
	}
</style>